package com.nuhu.dao;

import com.nuhu.pojo.RepairRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface MaintainRecordDao {
    @Insert("INSERT INTO  repair_record (appointment_date, issue_type, issue_details, rating, complaint, issue_Resolved, phone_number, signed_status)" +
            "VALUES (#{appointmentDate}, #{issueType}, #{issueDetails}, 0, null, 0, #{phoneNumber}, 0)")
    void insertMaintainRecord(RepairRecord repairRecord);

    @Update("UPDATE Repair_Record\n" +
            "SET Rating = TRUE, Issue_Resolved = TRUE\n" +
            "WHERE Phone_Number = #{phoneNumber};")
    void maintainSetIssueResolved(RepairRecord repairRecord);

    @Update("UPDATE Repair_Record\n" +
            "SET Signed_Status = TRUE\n" +
            "WHERE phone_number = #{phoneNumber};")
    void maintainSetIsSigned(RepairRecord repairRecord);

    @Select("SELECT Signed_Status\n" +
            "            FROM repair_record\n")
    RepairRecord maintainGetIsSigned();

    @Select("SELECT Appointment_Date, Issue_Type, Issue_Details, Phone_Number \n" +
            "FROM repair_record\n" +
            "ORDER BY Appointment_Date DESC\n" +
            "LIMIT 1;\n")
    RepairRecord selectMaintainRecord();
}
